package com.dustedpixels.jasmin.unit.impl;

import com.dustedpixels.jasmin.unit.Unit;
import com.dustedpixels.jasmin.unit.implbase.UnitImplBase;

/**
 * A unit which resamples the cycles by specified multipler and performs
 * resulting number of cycles on wrapped unit. The effect is like the wrapped
 * unit was performing given number times faster.
 */
public final class CycleResamplingUnit extends UnitImplBase {
    private final Unit wrappedUnit;

    private final float multiplier;

    private long cyclesProcessed;

    public CycleResamplingUnit(Unit wrappedUnit, float multiplier) {
        this.wrappedUnit = wrappedUnit;
        this.multiplier = multiplier;
        
        this.wrappedCyclesProcessed = 0;
        this.cyclesProcessed = 0;
    }

    public int processSlice() {
        int initialCycles = getCyclesProcessed();
        
        do {
            wrappedCyclesProcessed
        } while (getCyclesProcessed)
        
        cyclesProcessed += wrappedUnit.processSlice();
        if (multiplier < 1) {
            cyclesProcessed += wrappedUnit.processSlice();
        } else if (multiplier > 1) {
            
        } else {
            return wrappedUnit.processSlice();
        }
    }
    
    private long getCyclesProcessed() {
        return Math.round(cyclesProcessed * multiplier);
    }
}
